package com.core.zyyz.pcmc.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.core.zyyz.pcmc.domain.PcmcPage;
import com.core.zyyz.pcmc.service.PcmcPageService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.core.common.annotation.Log;
import com.core.common.core.controller.BaseController;
import com.core.common.core.domain.AjaxResult;
import com.core.common.enums.BusinessType;
import com.core.common.utils.poi.ExcelUtil;
import com.core.common.core.page.TableDataInfo;

/**
 * 页面Controller
 *
 * @author core
 * @date 2024-10-17
 */
@RestController
@RequestMapping("/pcmc/page")
public class PcmcPageController extends BaseController
{
    @Autowired
    private PcmcPageService pcmcPageService;

    /**
     * 查询页面列表
     */
    @PreAuthorize("@ss.hasPermi('pcmc:page:list')")
    @GetMapping("/list")
    public TableDataInfo list(PcmcPage pcmcPage)
    {
        startPage();
        List<PcmcPage> list = pcmcPageService.selectPcmcPageList(pcmcPage);
        return getDataTable(list);
    }

    /**
     * 导出页面列表
     */
    @PreAuthorize("@ss.hasPermi('pcmc:page:export')")
    @Log(title = "页面", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PcmcPage pcmcPage)
    {
        List<PcmcPage> list = pcmcPageService.selectPcmcPageList(pcmcPage);
        ExcelUtil<PcmcPage> util = new ExcelUtil<PcmcPage>(PcmcPage.class);
        util.exportExcel(response, list, "页面数据");
    }

    /**
     * 获取页面详细信息
     */
    @PreAuthorize("@ss.hasPermi('pcmc:page:query')")
    @GetMapping(value = "/{pageCode}")
    public AjaxResult getInfo(@PathVariable("pageCode") String pageCode)
    {
        return success(pcmcPageService.selectPcmcPageByPageCode(pageCode));
    }

    /**
     * 新增页面
     */
    @PreAuthorize("@ss.hasPermi('pcmc:page:add')")
    @Log(title = "页面", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PcmcPage pcmcPage)
    {
        return toAjax(pcmcPageService.insertPcmcPage(pcmcPage));
    }

    /**
     * 修改页面
     */
    @PreAuthorize("@ss.hasPermi('pcmc:page:edit')")
    @Log(title = "页面", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PcmcPage pcmcPage)
    {
        return toAjax(pcmcPageService.updatePcmcPage(pcmcPage));
    }

    /**
     * 删除页面
     */
    @PreAuthorize("@ss.hasPermi('pcmc:page:remove')")
    @Log(title = "页面", businessType = BusinessType.DELETE)
    @DeleteMapping("/{pageCodes}")
    public AjaxResult remove(@PathVariable String[] pageCodes)
    {
        return toAjax(pcmcPageService.deletePcmcPageByPageCodes(pageCodes));
    }
}
